package com.xmy.cultivate.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmy.cultivate.entity.Organization;
import com.xmy.cultivate.entity.views.ResDepartment;
import com.xmy.cultivate.mapper.OrganizationMapper;
import com.xmy.cultivate.service.IOrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 组织机构 服务实现类
 * </p>
 *
 * @author min
 * @since 2022-07-26
 */
@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements IOrganizationService {

    @Autowired
    OrganizationMapper organizationMapper;

    public List<Long> getOrganiztionId(Wrapper wrapper){
        return  organizationMapper.getOrganiztionId(wrapper);
    }

    @Override
    public String getSchoolName(Long schoolId) {
        return organizationMapper.getSchoolName(schoolId);
    }

    @Override
    public List<Organization> getOrganiztionList(Integer type){
        return organizationMapper.getOrganiztionList(type);
    }


    @Override
    public List<ResDepartment> getOrganiztionAndStaffList(String schoolName,String staffName,Integer status, Integer type, String staffStatus, String staffType, String staffJustType){
        return organizationMapper.getOrganiztionAndStaffList(schoolName,staffName,status,type,staffStatus,staffType,staffJustType);
    }

    @Override
    public List<Long> getOrganizationChidAll(Long schoolId,Integer status){
        return organizationMapper.getOrganizationChidAll(schoolId,status);
    }

    @Override
    public Organization getOneRand(){
        return organizationMapper.getOneRand();
    }

    @Override
    public Organization getOneForAliAccount(String aliAccount){

        QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
        organizationQueryWrapper.eq("ali_account",aliAccount);
        organizationQueryWrapper.eq("status",1);
        organizationQueryWrapper.last("limit 1");
        Organization organization = organizationMapper.selectOne(organizationQueryWrapper);
        return organization;
    }
}
